package arduino;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import java.awt.event.*;
import java.awt.*;
import java.util.Vector;
import java.util.concurrent.*;

public class ApplicationFrame extends JFrame{
	int iNumberOfMenu = 5;
	int iNumberOfMenuItems[] = {10, 8, 6, 4, 2};
	JMenu menu[] ;
	JMenuItem menuItems[][];
	int pressurePerMenu = 0 ;
	
	int currentSelectedMenu = -1;
	int currentSelectedMenuItem = -1;
	private MessageQueue msq ;
	//private ProcessMessageQueue processMessageQueue ;
	//private EventQueue	eventQueue;
	//public static MyEventManager myEventManager;
	//private int sensorAStatus;
	//private int sensorBStatus;
	public ApplicationFrame(){
		super("Browsing through a menu by pressure sensors.") ;

		// create the menu bar
		JMenuBar bar = new JMenuBar();
		setJMenuBar(bar) ;
		
		menu = new JMenu[iNumberOfMenu] ;
		menuItems = new JMenuItem[5][];
		for(int i = 0 ; i < iNumberOfMenu ; i++){
			menu[i] = new JMenu("Menu"+(i+1));
			// add menu items
			menuItems[i] = new JMenuItem[iNumberOfMenuItems[i]];
			for(int j = 0 ; j < iNumberOfMenuItems[i]; j++){
				menuItems[i][j] = new JMenuItem("MenuItem"+(i+1)+"_"+(j+1));
				menu[i].add(menuItems[i][j]);
			}
			bar.add(menu[i]);
		}							
		
		ExecutorService threadExecutors = Executors.newFixedThreadPool(2);
		
		msq = new MessageQueue();
		//eventQueue = new EventQueue();
		//myEventManager = new MyEventManager(eventQueue) ;
		try{
			//threadExecutors.execute(new ProcessMessageQueue(msq,eventQueue)) ;
			threadExecutors.execute(new ProcessMessageQueue(msq)) ;
			//threadExecutors.execute(myEventManager) ;
		}
		catch(Exception exception){
			exception.printStackTrace();
		}
		// initialize the serial communication
		SerialTest serialComm = new SerialTest();
		serialComm.initialize(msq);
		System.out.println("Serial communication started");

		// find pressure anchor points for each menu
		pressurePerMenu = 800/iNumberOfMenu ;
		//sensorAStatus = 0 ;
		//sensorBStatus = 0 ;
		
	}
	
	
	
	public static void main(String[] args){// throws Exception {
		//SerialTest main = new SerialTest();
		//main.initialize();
		System.out.println("Application Started");
		ApplicationFrame app = new ApplicationFrame();
		//myEventManager.AddEventListener(app);
		//app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//app.setSize(500,200) ;
		//app.setVisible(true);
	}
}
